/*
	Title:		Elders Program
	Author:		Bruce Frick
	Purpose:	report handler
*/

function bindElements(){
	
	$(".DateFrom, .DateTo").datepicker({ 
		dateFormat: 'mm/dd/yy', changeYear: true, changeMonth: true, yearRange: '2000:2010', autoSize: true,
		prevText: 'Earlier', nextText: 'Later', showOn: 'button', 
		buttonImage: '/CFIDE/scripts/ajax/resources/cf/images/DateChooser.png', buttonImageOnly: true
	});	
	
	$("#ServicePlanTarget, #ServicePlanTargetPDF, #ServicePlanTargetXLS," +  
		"#BillableServices, #BillableServicesPDF, #BillableServicesXLS," +
		"#UnDupSerivces, #UnDupSerivcesPDF," + 
		"#MasterActivity, #MasterActivityPDF," + 
		"#MedicaidBilling, #MedicaidBillingPDF," +
		"#BillingReport, #BillingReportPDF, #BillingReportXLS," + 
		"#NoPriorityList, #NoPriorityListPDF, #NoPriorityListXLS," + 
		"#NoProviderList, #NoProviderListPDF, #NoProviderListXLS," + 
		"#MailingList, #MailingListPDF, #MailingListXLS," + 
		"#ActiveClientList, #ActiveClientListPDF, #ActiveClientListXLS," + 
		"#ServicesReport, #ServicesReportPDF, #ServicesReportXLS," + 
		"#ProviderDistribution,#ProviderDistributionPDF," + 
		"#Ethnicity, #EthnicityPDF," + 
		"#RegionalCorp, #RegionalCorpPDF," +
		"#SupervisorSign").bind('click', function(){
		reportSubmit(this, "form_reports");
	});
}


function reportSubmit(reportObj, form){
	var parent = $(reportObj).parent();
	var children = $(reportObj).parent().children();
	var api = $("#" + parent[0].id).children("input[type='hidden']").val();
	var isPDF = $(reportObj).attr("id").substr( $(reportObj).attr("id").length - 3 );
	var isXLS = $(reportObj).attr("id").substr( $(reportObj).attr("id").length - 3 );
	( isPDF == "PDF"  ) ? api = api + "_pdf" : false;
	( isXLS == "XLS"  ) ? api = api + "_xls" : false;
	var date_from = $("#" + parent[0].id).children(".DateFrom").val();
	var date_to = $("#" + parent[0].id).children(".DateTo").val();
	var provider = $("#" + parent[0].id).children(".Provider").val();
	var billing_type = $("#" + parent[0].id).children(".BillingType").val();
	$("#" + form).attr('action', 
		api + 
		"&DateFrom=" + date_from + 
		"&DateTo=" + date_to +
		( ( provider ) ? "&ProviderID=" + provider : "") + 
		( ( billing_type ) ? "&BillingType=" + billing_type : "")
	);
	$("#" + form).submit();
	
	return false;
}


$(function() {
	bindElements();	
});